//
//  AstStmt.h
//  LightBasic
//
//  Created by Albert on 02/04/2011.
//  Copyright 2011 LightBasic Development Team. All rights reserved.
//
#pragma once


/**
 * Base class for statements (keywords)
 */
struct AstStatement : Ast {};


/**
 * Statement list
 */
struct AstStmtList : Ast
{
    /// typedef for container
    typedef std::vector<AstStatement *> List;
    
    /// The statements
    List stmts;
    
    /// Declare this ast node
    DECLARE_AST();
    
    /// clean list
    virtual ~AstStmtList()
    {
        for (List::iterator iter = stmts.begin(); iter != stmts.end(); iter++) {
            delete *iter;
        }
    }
};


#if 0


/**
 * Type declaration
 */
struct AstTypeDecl : AstStatement
{
    /// the identifier
    Token * ident;
    
    /// pointer level
    int deref;
    
    /// is reference
    bool isRef;
    
    /// is pointer (deref == 0)
    bool isPtr;
    
    /// is conts ?
    bool isConst;
    
    /// creator
    AstTypeDecl(Token * ident, int deref, bool isRef, bool isConst) : ident(ident), deref(deref), isRef(isRef), isPtr(deref > 0), isConst(isConst) {}
    
    /// Declare this ast node
    DECLARE_AST();
    
    // release ident
    virtual ~AstTypeDecl()
    {
        if (ident != NULL) delete ident;
    }
};


/**
 * type declaration
 */
struct AstVarDecl : AstStatement
{
    /// the type
    AstTypeDecl * type;
    
    /// the identifier
    AstExprIdent * ident;
    
    /// default value
    AstExpression * def;
    
    /// create
    AstVarDecl(AstTypeDecl * type, AstExprIdent * ident, AstExpression * def) : type(type), ident(ident), def(def) {}
    
    /// Declare this ast node
    DECLARE_AST();
    
    // release ident
    virtual ~AstVarDecl()
    {
        if (type != NULL) delete type;
        if (ident != NULL) delete ident;
        if (def != NULL) delete def;
    }
};


/**
 * TypeDecl list
 */
struct AstVarDeclList : AstStatement
{
    /// container typedef
    typedef std::list<AstVarDecl *> List;
    
    /// type declarations
    List vars;
    
    /// create
    AstVarDeclList() {}
    
    /// Declare this ast node
    DECLARE_AST();
    
    /// clear
    virtual ~AstVarDeclList()
    {
        for (List::iterator iter = vars.begin(); iter != vars.end(); iter++) {
            delete *iter;
        }
    }
};


/**
 * Assign statement
 * need this???
 */
struct AstStmtAssign : AstStatement
{
    /// the type
    AstTypeDecl * type;
    
    /// the identifier
    AstExprIdent * ident;
    
    /// default value
    AstExpression * value;
    
    /// create
    AstStmtAssign(AstTypeDecl * type, AstExprIdent * ident, AstExpression * value) : type(type), ident(ident), value(value) {}
    
    /// Declare this ast node
    DECLARE_AST();
    
    // release ident
    virtual ~AstStmtAssign()
    {
        if (type != NULL) delete type;
        if (ident != NULL) delete ident;
        if (value != NULL) delete value;
    }
};

#endif
